<template>
	<view class="index-page">
		<!-- <keep-alive>
		</keep-alive> -->
		<!-- v-if="isShowComponent" -->
		<component :is="currentComponent"></component>
		<!-- <view class="firm" v-if="nowEndType == 1">
			<FirmCart v-if="nowPageId == 1" />
			<FirmDriver v-if="nowPageId == 2" />
			<FirmSettlementCenter v-if="nowPageId == 3" />
			<FirmMy v-if="nowPageId == 4" />
		</view>
		<view class="drivers" v-if="nowEndType==2">
			<driversOrderTakingCenter v-if="nowPageId==1" />
			<driversMissionCenter v-if="nowPageId==2" />
			<driversSettlementCenter v-if="nowPageId==3" />
			<driversMy v-if="nowPageId==4" />
		</view>
		<view class="consumption" v-if="nowEndType==3">
			<consumptionHome v-if="nowPageId == 0" />
			<consumptionDataCenter v-if="nowPageId == 1" />
			<consumptionMy v-if="nowPageId == 2" />
		</view>
		<view class="consumptionAdmin" v-if="nowEndType==4">
			<consumptionAdminHome v-if="nowPageId == 1" />
			<consumptionAdminDataCenter v-if="nowPageId == 2" />
			<consumptionAdminMy v-if="nowPageId == 3" />
		</view> -->
		<Tabbar />
	</view>
</template>

<script setup lang="ts">
	// 运企端页面
	// 车辆管理
	import FirmCart from '@/pages/firm/cart/cart.vue';
	// 驾驶员管理
	import FirmDriver from '@/pages/firm/driver/driver.vue';
	// 结算中心
	import FirmSettlementCenter from '@/pages/firm/settlementCenter/settlementCenter.vue';
	// 我的
	import FirmMy from '@/pages/firm/my/my.vue';


	// 司机端页面
	// 接单中心
	import driversOrderTakingCenter from '@/pages/drivers/orderTakingCenter/OrderTakingCenter.vue'
	// 任务中心
	import driversMissionCenter from '@/pages/drivers/missionCenter/missionCenter.vue'
	// 结算中心
	import driversSettlementCenter from '@/pages/drivers/settlementCenter/settlementCenter.vue'
	// 我的
	import driversMy from '@/pages/drivers/my/my.vue'


	// 消纳端页面
	// 首页
	import consumptionHome from '@/pages/consumption/home/home.vue'
	// 数据中心
	import consumptionDataCenter from '@/pages/consumption/dataCenter/dataCenter.vue'
	// 我的
	import consumptionMy from '@/pages/consumption/my/my.vue'

	// 消纳管理端页面
	// 首页
	import consumptionAdminHome from '@/pages/consumptionAdmin/home/home.vue'
	// 数据中心
	import consumptionAdminDataCenter from '@/pages/consumptionAdmin/dataCenter/dataCenter.vue'
	// 我的
	import consumptionAdminMy from '@/pages/consumptionAdmin/my/my.vue'
	import Tabbar from '@/components/tabbar/tabbar.vue';
	import { useUserStore } from '@/stroes';
	import { computed } from 'vue';
	import {
		onLoad
	} from "@dcloudio/uni-app"
	const userStore = useUserStore()
	// app端 // 1--company 运企管理  2--dirver 司机端  3--terminal_sign 消纳端  4--terminal_manage 消纳管理端
	/* const nowEndType = computed(() => {
		let num = 3;
		switch (userStore.nowEndType.roleCode) {
			case 'company':
				num = 1
				break;
			case 'driver':
				num = 2
				break;
			case 'terminal_sign':
				num = 3
				break;
			case 'terminal_manage':
				num = 4
				break;
		}
		return num
	})
	// 当前页面id // 首页，数据中心，个人中心
	const nowPageId = computed(() => {
		return userStore.nowPageId
	}) */
	const endList = [
		{
			endType: 'company',
			pages: [FirmCart, FirmDriver, FirmSettlementCenter, FirmMy]
		},
		{
			endType: 'driver',
			pages: [driversOrderTakingCenter, driversMissionCenter, driversSettlementCenter, driversMy]
		},
		{
			endType: 'terminal_sign',
			pages: [consumptionHome, consumptionDataCenter, consumptionMy]
		},
		{
			endType: 'terminal_manage',
			pages: [consumptionAdminHome, consumptionAdminDataCenter, consumptionAdminMy]

		}];
	const currentComponent = computed(() => {
		let roleCode = userStore.nowEndType?.roleCode
		if (roleCode) {
			let nowItem = endList.find(item => item.endType == roleCode)
			if (nowItem) {
				return nowItem.pages[userStore.nowPageId]
			}
		}
		console.log('未找到页面');
	})
	/* watch([userStore.nowEndType?.roleCode, userStore.nowPageId], () => {
		isShowComponent.value = false;
		setTimeout(() => {
			isShowComponent.value = true;
		})
		nextTick(() => {

		})
	}) */
	/* 
	const currentComponent = ref(null)
	watchEffect(() => {
		isShowComponent.value = false
		let roleCode = userStore.nowEndType?.roleCode
		if (roleCode) {
			let nowItem = endList.find(item => item.endType == roleCode)
			if (nowItem) {
				currentComponent.value = nowItem.pages[userStore.nowPageId]
				isShowComponent.value = true
			}
		}
		console.log('未找到页面');
	}) */


	onLoad(() => {
		uni.hideTabBar()
	})
</script>

<style>
	/* .index-page {
		color: $primary-color;
		background-color: #F0F3F8;
	}

	.container {
		height: 100vh;
		background-color: #F0F3F8;
	}

	*/
</style>